<script>
function delgoods(obj){
 for(obj=obj.parentNode; obj.tagName!='TR'; obj=obj.parentNode);
 obj.parentNode.removeChild(obj);
}

function calculate(){
 var iList = document.getElementsByName('aPrice[]');
}
</script>

<form method='post' action='index.php?ctl=order/order&act=toEdit' class="tableform" id="orderEdit" extra="subOrder" target="{update:'messagebox'}">
  <h4><{t}>商品信息<{/t}></h4>
 <div class="division" id="orderItemList">
 <{include file="order/edit_items.html"}>
 </div>
 <input id="add_order_id" TYPE="hidden" value="<{$order.order_id}>" >
 <input id="add_cost_item" TYPE="hidden" value="<{$order.cost_item}>" >
 <input id="add_payment" TYPE="hidden" value="<{$order.payment}>" >
 <h4><{t}>订单信息<{/t}></h4>
 <div class="division">
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th><{t}>订单号：<{/t}></th>
    <td><{$order.order_id}></td>
    <th><{t}>下单日期：<{/t}></th>
    <td><{$order.createtime|cdate:'SDATE_STIME'}></td>
  </tr>
   <tr>
    <th><{t}>商品总金额：<{/t}></th>
    <td><input id="iditem_amount" TYPE="text" name="cost_item" value="<{$order.cost_item}>" size=10 disabled="disabled"></td>
    <th><{t}>配送方式：<{/t}></th>
    <td><select name=shipping_id><{html_options options=$order.selectDelivery selected=$order.shipping_id}></select></td>
  </tr>
   <tr>
    <th><{t}>配送费用：<{/t}></th>
    <td><{input id="idcost_freight" class='item itemrow' name="cost_freight" value=$order.cost_freight type="unsigned" size=10}></td>
    <th><{t}>支付方式：<{/t}></th>
    <td>
        <select name=payment><{html_options options=$order.selectPayment selected=$order.payment}></select>
        &nbsp;&nbsp;
        <{foreach from=$order.extendCon item=item key=key}>
            <{$item}>&nbsp;&nbsp;
        <{/foreach}></td>
  </tr>
  <tr>
    <th><{t}>保价：<{/t}></th>
    <td><{input id="idcost_protect" class="item itemrow" type="unsigned" name="cost_protect" size=10 value=$order.cost_protect }><{t}> 是否要保价<{/t}><input id="idis_protect" name="is_protect" type='checkbox' value='true' <{if $order.is_protect == 'true'}>checked="checked"<{/if}>></td>
    <th><{t}>商品重量：<{/t}></th>
    <td><{input name=weight type="unsigned" class=inputstyle size=10 value=$order.weight }></td>
  </tr>
  <tr>
    <th><{t}>支付手续费：<{/t}></th>
    <td><{input id="idcost_payment" class='item itemrow' name=cost_payment type="unsigned" size=10 value=$order.cost_payment }></td>
    <th><{t}>发票抬头：<{/t}></th>
    <td><{input id="idtax_company" name="tax_company" value=$order.tax_company}></td>
  </tr>
   <tr>
    <th><{t}>税金：<{/t}></th>
    <td><{input id="idcost_tax" class='item itemrow' name="cost_tax" type="unsigned" size=10 value=$order.cost_tax }><{t}> 是否开发票<{/t}><input id="idis_tax" name="is_tax" type='checkbox' value='true' <{if $order.is_tax == 'true'}>checked="checked"<{/if}>></td>
    <th><{t}>支付币别：<{/t}></th>
    <td><{if $order.order_id == ''}><{html_options options=$order.curList selected=$order.currency}><{else}><{$order.cur_name}><{if $order.cur_rate != 1}>(<{$order.cur_rate}>)<{/if}><{/if}></td>
  </tr>
   <tr>
    <th><{t}>促销优惠金额：<{/t}></th>
    <td><input id="idpmt_amount" class='item itemrow' name="pmt_amount" value="<{$order.pmt_amount}>" size=10></td>
    <th><{t}>订单折扣或涨价：<{/t}></th>
    <td><input id="iddiscount" class='item itemrow' name="discount" value="<{$order.discount}>" size=10><br>要给顾客便宜100元，则输入"-100";要提高订单价格100元，则输入"100".
  </tr>
   <tr>
    <th><{t}>订单总金额：<{/t}></th>
    <td><input id="idtotal_amount" name=total_amount value="<{$order.total_amount}>" disabled="disabled"></td>

</td>
  </tr>
  
</table>
</div>

<h4><{t}>购买人信息<{/t}></h4>
<div class="division">
  <{if $order.order_id == ''}>
  <input TYPE="text" NAME="uname" value='' class=inputstyle size=15>
  <input TYPE="button"  class=inputstyle value="导入会员" onClick="seluser(adminForm.uname.value)">
  <input TYPE="button"  class=inputstyle value="非会员" onClick="seluser('anonymous')">
  <input TYPE="hidden" name="userid" value="{userid}"> 
  <{/if}>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  
   <tr>
    <th><{t}>姓名：<{/t}></th>
    <td><{$order.member.name}></td>
    <th><{t}>会员用户名：<{/t}></th>
    <td><{$order.member.uname}></td>
  </tr>
   <tr>
    <th><{t}>联系电话：<{/t}></th>
    <td><{$order.member.tel}></td>
    <th><{t}>Email地址：<{/t}></th>
    <td><{$order.member.email}></td>
  </tr>
   <tr>
    <th><{t}>地区：<{/t}></th>
    <td><{$order.member.area|region}></td>
    <th><{t}>邮政编码：<{/t}></th>
    <td><{$order.member.zip}></td>
  </tr>
   <tr>
    <th><{t}>地址：<{/t}></th>
    <td><{$order.member.addr}></td>
    <th></th>
    <td></td>
  </tr>
</table>
</div>


<{if $order.is_delivery == 'Y'}>
 <h4><{t}>收货人信息<{/t}></h4>
 <div class="division" id="order_edit_receiver">
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
   <tr>
    <th><{t}>收货人姓名：<{/t}></th>
    <td><{input type="text" NAME="ship_name" required="true" value=$order.ship_name }>*</td>
    <th><{t}>联系手机：<{/t}></th>
    <td><input type="text" NAME="ship_mobile" value="<{$order.ship_mobile}>" class=inputstyle></td>
  </tr>
   <tr>
    <th><{t}>联系电话：<{/t}></th>
    <td><{input type="order_tel" NAME="ship_tel" class=inputstyle value=$order.ship_tel}></td>
    <th><{t}>Email地址：<{/t}></th>
    <td><{if $order.member}><{$order.ship_email}><{else}><{input type="email" NAME="ship_email" value=$order.ship_email }><{/if}></td>
  </tr>
   <tr>
    <th><{t}>送货时间：<{/t}></th>
    <td><input type="text" NAME="ship_time" value="<{$order.ship_time}>" class=inputstyle></td>
    <th><{t}>邮政编码：<{/t}></th>
    <td><{input  NAME="ship_zip"  class=inputstyle value=$order.ship_zip}></td>
  </tr>
   <tr>
    <th><{t}>收货地区：<{/t}></th>
    <td><{input type="region" name="ship_area" required="true" value=$order.ship_area}>*</td>
    <th><{t}>收货地址：<{/t}></th>
    <td><{input type="text" NAME="ship_addr" required="true" class=inputstyle value=$order.ship_addr}>*</td>
  </tr>
  
</table>
</div>    
 <{/if}> 
<!--
<div class="table-action">
    <{button label="提交" type="submit" name='butsubmit'}>
</div>-->


</form>
<script>
 var itemAmount=0;
 $ES(".itemrow","moneyItems").each(function(item, index, itobj){
 item.addEvent('change',function(e){
  e=new Event(e);
  var ipt=e.target;
  if(ipt.className.split('_').length > 1){
   var key=(ipt.className.split('_')[1]).toInt();
   var result=$E('.itemPrice_'+key,'moneyItems').getValue().toFloat()*$E('.itemNum_'+key,'moneyItems').getValue().toInt();
   $E('.itemSub_'+key).setText(result);
  }
  countF();
  });
 });
 
 function countF(){
  $('iditem_amount').value=function(){
    var count=0;
    $ES(".itemCount","moneyItems").each(function(item){
     count += item.getText().toFloat()*1;
    });
    return count;
   }();
  $('idtotal_amount').value=function(){
    var cost_protect = 0;
    if($('idis_protect').checked){
        cost_protect = $('idcost_protect').value.toFloat();
    }
    var cost_tax = 0;
    if($('idis_tax').checked){
        cost_tax = Number($('idcost_tax').value);
    }
    var count=0;
    count = Number($('iditem_amount').value) + cost_protect + $('idcost_freight').value.toFloat() + Number($('idcost_payment').value) + cost_tax + Number($('iddiscount').value) - Number($('idpmt_amount').value);
    return count.round(2);
   }();
 }
 
 $('idis_protect').addEvent('click',function(e){
  $('idcost_protect').disabled = !$('idis_protect').checked;
  countF();
 });
 
 $('idis_tax').addEvent('click',function(e){
  $('idcost_tax').disabled = !$('idis_tax').checked;
  countF();
//  if($('idis_tax').checked){
//   $('idtax_company').style.display = 'block';
//  }else{
//   $('idtax_company').style.display = 'none';
//  }
 });

$('idcost_tax').disabled = !$('idis_tax').checked;

 if(!$('idis_protect').checked){
  $('idcost_protect').disabled = true;
 }
var extra_validator={};
if(!extra_validator['subOrder']){
  extra_validator['subOrder'] ={
    'order_tel':['请至少输入联系电话和联系手机中的一项',function(f,i){
        var tel = $('order_edit_receiver').getElement('input[name=ship_tel]').getProperty('value');
        var mob = $('order_edit_receiver').getElement('input[name=ship_mobile]').getProperty('value');
        if(tel.trim() == '' && mob.trim() == ''){
          return false;
        }else{
            return true;
        }
      }]
  };
}
</script>
